import Vue from 'vue'
import Router from 'vue-router'
import axios from 'axios'
// 登录页面
import login from '@/components/login/login'

import home from '@/components/home/home'

//工作任务
//今日任务（组员）
import Todaytask from '@/components/todaytask/todaytask'
//进入任务（组长）
import todaytaskleader from '@/components/todaytask/todaytaskleader'
//今日任务（助理）
import Todaytask2 from '@/components/todaytask/todaytask2'
import Dove from '@/components/todaytask/dove'
//待办任务助理
import tasktodo from '@/components/todaytask/tasktodo'
//待办任务专员
import tasktodocommissioner from '@/components/todaytask/tasktodocommissioner'
//待办任务交付
import tasktodojiaofu from '@/components/todaytask/tasktodojiaofu'
//未反馈消息助理
import unfeedbackmessage from '@/components/todaytask/unfeedbackmessage'
//未反馈消息专员
import unfeedmember from '@/components/todaytask/unfeedmember'
import workrecord from '@/components/todaytask/workrecord'
import workrecord1 from '@/components/todaytask/workrecord1'
import workrecord2 from '@/components/workrecord/workrecord2'
import workjiaofu from '@/components/todaytask/workjiaofu'
//审批记录
import approvalRecord from '@/components/approvalRecord/approvalRecord'
//客户沟通communication
import communication from '@/components/communication/communication'
import communication1 from '@/components/communicationZhuli/communication1'
import followupCommunication from '@/components/communicationZhuli/followupCommunication'


// 职位管理页面
import Jobdemand from '@/components/Jobdemand/Jobmanage'
import Jobdemand1 from '@/components/Jobdemand/Jobmanage1'
import templatemanage from '@/components/templatemanage/templatemanage'
//人员简历
import personnelresume from '@/components/personnelresume/personnelresume'


//简历管理
// 筛选简历页面
import screenresume from '@/components/screenresume/screenresume'
// 简历模板预览
import modelmanage from '@/components/screenresume/modelmanage'
// 简历上传页面
import resumeupload from '@/components/resumeupload/resumeupload'
// 简历推送页面
import resumepush from '@/components/resumepush/resumepush'
// 简历反馈页面
import resumefeedback from '@/components/resumefeedback/resumefeedback'
import resumefeedback1 from '@/components/resumefeedback/resumefeedback1'
// 简历入库页面
import inStorage from '@/components/inStorage/inStorage'
//简历审核页面
import resumereview from '@/components/resumereview/resumereview'
//已推简历页面
import presentedresume from '@/components/presentedresume/presentedresume'
//简历库页面
import resumelibrary from '@/components/resumelibrary/resumelibrary'
//简历确认页面
import resumeconfirm from '@/components/resumeconfirm/resumeconfirm'


//面试管理
// 面试邀约页面
import telesolicit from '@/components/telesolicit/telesolicit'
import telesolicit1 from '@/components/telesolicit/telesolicit1'

// 现场面试页面
import fieldinterview from '@/components/fieldinterview/fieldinterview'
import fieldinterview1 from '@/components/fieldinterview/fieldinterview1'

// 面试跟踪页面
import interviewtrack from '@/components/interviewtrack/interviewtrack'
import interviewtrack1 from '@/components/interviewtrack/interviewtrack1'

// 面试结果页面
import interviewresult from '@/components/interviewresult/interviewresult'
import interviewresult1 from '@/components/interviewresult/interviewresult1'

// 面试反馈页面
import interviewfeedback from '@/components/interviewfeedback/interviewfeedback'
import interviewfeedback1 from '@/components/interviewfeedback/interviewfeedback1'

// 技术面试页面
import technicalInterview from '@/components/technicalInterview/technicalInterview'
// 技术面试结果页面
import technicalResults from '@/components/technicalResults/technicalResults'

// 入职管理
// 入职申请
import entryapply from '@/components/entryapply/entryapply'

// 入职办理
import entryhandle from '@/components/entryhandle/entryhandle'

// 进场跟踪
import entrytracking from '@/components/entrytracking/entrytracking'

// 数据统计

//外包人员增减表
import outsourcedsheet from '@/components/outsourcedsheet/outsourcedsheet'
//入职人员信息表
import employinfosheet from '@/components/employinfosheet/employinfosheet'
//工作统计表
import workstatistics from '@/components/workstatistics/workstatistics'
// 简历推送统计表
import resumepushstatistics from '@/components/resumePushStatistics/resumePushStatistics'

// 入职统计表
import entrystatistics from '@/components/entrystatistics/entrystatistics'
//离职统计表
import resignationInformation from '@/components/resignationInformation/resignationInformation'

import entryInformation from '@/components/entryInformation/entryInformation'

//系统设置
// 角色管理页面
import rolemanage from '@/components/rolemanage/rolemanage'
// 用户管理页面
import custmanage from '@/components/custmanage/custmanage'
// 职位设置页面
import postmanage from '@/components/postmanage/postmanage'
//客户设置页面
import employunitset from '@/components/employunitset/employunitset'
// 地区设置页面
import districtmanage from '@/components/districtmanage/districtmanage'
// 面试流程
import interviewprocess from '@/components/interviewprocess/interviewprocess'
// 权限设置
import permissionset from '@/components/persettings/permissionset'
//菜单设置
import menuset from '@/components/persettings/menuset'
//数据字典
// 组织结构页面
import orgstructure from '@/components/orgstructure/orgstructure'
//任务设置页面
import tasksetting from '@/components/tasksetting/tasksetting'
//
import DictionaryValue from '@/components/DictionaryValue/DictionaryValue'
import marquee from '@/components/marquee/marquee'
import timeValue from '@/components/timeValue/timeValue'
// 组织结构添加
import teamconfigure from '@/components/custmanage/teamconfigure'
//光荣榜
import honour from '@/components/honour/honour'

import mailtemplate from '@/components/mailtemplate/mailtemplate'

import notFound from '@/components/404/notfound'

import tagsView from '../store/modules/tagsView'

//背景调查
import backchecked from '../components/backchecked/backchecked'

// 访问记录
import accessInfo from '../components/accessInfo/accessInfo'

// 数据字典
import datadictionary from '../components/datadictionary/datadictionary'

//职位设置
import positionset from '../components/positionset/positionset'

Vue.use(Router)


const originalPush = Router.prototype.push;

Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


var router = new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component: login
    }, {
      path: '/honour',
      name: 'honour',
      component: honour
    }, {
      path: '/home',
      name: 'home',
      component: home,
      redirect: '/home/jobdemand',
      children: [
        {
          path: 'todaytask',
          name: 'todaytask',
          component: Todaytask,
          meta: {
            title: '今日任务',
            code: '1-1'
          }
        },
        {
          path: 'todaytaskleader',
          name: 'todaytaskleader',
          component: todaytaskleader,
          meta: {
            title: '今日任务',
            code: '1-1-2'
          }
        },
        {
          path: 'todaytask2',
          name: 'todaytask2',
          component: Todaytask2,
          meta: {
            title: '今日任务',
            code: '1-2'
          }
        },
        {
          path: 'dove',
          name: 'dove',
          component: Dove,
          meta: {
            title: '时间确认',
            code: '1-2-1'
          }
        },
        {
          path: 'tasktodo',
          name: 'tasktodo',
          component: tasktodo,
          meta: {
            title: '待办任务',
            code: '1-3'
          }
        },
        {
          path: 'tasktodocommissioner',
          name: 'tasktodocommissioner',
          component: tasktodocommissioner,
          meta: {
            title: '待办任务',
            code: '1-3-1'
          }
        },
        {
          path: 'tasktodojiaofu',
          name: 'tasktodojiaofu',
          component: tasktodojiaofu,
          meta: {
            title: '待办任务(交付)',
            code: '1-3-2'
          }
        },
        {
          path: 'unfeedbackmessage',
          name: 'unfeedbackmessage',
          component: unfeedbackmessage,
          meta: {
            title: '未反馈消息',
            code: '1-4'
          }
        },
        {
          path: 'unfeedmember',
          name: 'unfeedmember',
          component: unfeedmember,
          meta: {
            title: '未反馈消息',
            code: '1-4-1'
          }
        },
        {
          path: 'workrecord',
          name: 'workrecord',
          component: workrecord,
          meta: {
            title: '工作记录',
            code: '1-5'
          }
        },
        {
          path: 'workrecord1',
          name: 'workrecord1',
          component: workrecord1,
          meta: {
            title: '工作记录',
            code: '1-5-1'
          }
        },
        {
          path: 'workrecord2',
          name: 'workrecord2',
          component: workrecord2,
          meta: {
            title: '工作记录',
            code: '1-5-2'
          }
        },
        {
          path: 'workjiaofu',
          name: 'workjiaofu',
          component: workjiaofu,
          meta: {
            title: '工作记录(交付)',
            code: '1-5-3'
          }
        }, {
          path: 'communication',
          name: 'communication',
          component: communication,
          meta: {
            title: '客户沟通',
            code: '1-6'
          }
        }, {
          path: 'communication1',
          name: 'communication1',
          component: communication1,
          meta: {
            title: '客户沟通(助理)',
            code: '1-7'
          }
        }, {
          path: 'followupCommunication',
          name: 'followupCommunication',
          component: followupCommunication,
          meta: {
            title: '跟进客户沟通',
            code: '1-8'
          }
        }, {
          path: 'approvalRecord',
          name: 'approvalRecord',
          component: approvalRecord,
          meta: {
            title: '审批记录',
            code: '1-9'
          }
        },
        {
          path: 'jobdemand',
          name: 'jobdemand',
          component: Jobdemand,
          meta: {
            title: '职位管理',
            code: '2'
          }
        },
        {
          path: 'jobdemand1',
          name: 'Jobdemand1',
          component: Jobdemand1,
          meta: {
            title: '职位管理(助理)',
            code: '2-1'
          }
        },
        {
          path: 'positionset',
          name: 'positionset',
          component: positionset,
          meta: {
            title: '职位修改',
            code: '2-2'
          }
        },
        {
          path: 'screenresume',
          name: 'screenresume',
          component: screenresume,
          meta: {
            title: '简历筛选',
            code: '3-1'
          }
        },
        {
          path: 'resumeupload',
          name: 'resumeupload',
          component: resumeupload,
          meta: {
            title: '简历上传',
            code: '3-2'
          }
        },
        {
          path: 'resumepush',
          name: 'resumepush',
          component: resumepush,
          meta: {
            title: '简历推送',
            code: '3-5'
          }
        },
        {
          path: 'resumefeedback',
          name: 'resumefeedback',
          component: resumefeedback,
          meta: {
            title: '简历反馈(助理)',
            code: '3-6'
          }
        },
        {
          path: 'resumefeedback1',
          name: 'resumefeedback1',
          component: resumefeedback1,
          meta: {
            title: '简历反馈(专员)',
            code: '3-7'
          }
        },
        {
          path: 'instorage',
          name: 'instorage',
          component: inStorage,
          meta: {
            title: '简历入库',
            code: '3-8'
          }
        },
        {
          path: 'resumereview',
          name: 'resumereview',
          component: resumereview,
          meta: {
            title: '简历审核',
            code: '3-9'
          }
        },
        {
          path: 'presentedresume',
          name: 'presentedresume',
          component: presentedresume,
          meta: {
            title: '已推简历',
            code: '4-0'
          }
        },
        {
          path: 'resumelibrary',
          name: 'resumelibrary',
          component: resumelibrary,
          meta: {
            title: '简历库',
            code: '4-0-1'
          }
        },
        {
          path: 'resumeconfirm',
          name: 'resumeconfirm',
          component: resumeconfirm,
          meta: {
            title: '简历确认',
            code: '4-0-2'
          }
        },
        {
          path: 'telesolicit',
          name: 'telesolicit',
          component: telesolicit,
          meta: {
            title: '面试邀约(助理)',
            code: '4-1'
          }
        },
        {
          path: 'telesolicit1',
          name: 'telesolicit1',
          component: telesolicit1,
          meta: {
            title: '面试邀约(专员)',
            code: '4-1-1'
          }
        },
        {
          path: 'fieldinterview',
          name: 'fieldinterview',
          component: fieldinterview,
          meta: {
            title: '现场面试(助理)',
            code: '4-2'
          }
        },
        {
          path: 'fieldinterview1',
          name: 'fieldinterview1',
          component: fieldinterview1,
          meta: {
            title: '现场面试(专员)',
            code: '4-2-1'
          }
        },
        {
          path: 'interviewtrack',
          name: 'interviewtrack',
          component: interviewtrack,
          meta: {
            title: '面试跟踪(助理)',
            code: '4-3'
          }
        },
        {
          path: 'interviewtrack1',
          name: 'interviewtrack1',
          component: interviewtrack1,
          meta: {
            title: '面试跟踪(专员)',
            code: '4-3-1'
          }
        },
        {
          path: 'interviewresult',
          name: 'interviewresult',
          component: interviewresult,
          meta: {
            title: '面试结果(助理)',
            code: '4-4'
          }
        },
        {
          path: 'interviewresult1',
          name: 'interviewresult1',
          component: interviewresult1,
          meta: {
            title: '面试结果(专员)',
            code: '4-4-1'
          }
        },
        {
          path: 'interviewfeedback',
          name: 'interviewfeedback',
          component: interviewfeedback,
          meta: {
            title: '面试反馈',
            code: '4-5'
          }
        },
        {
          path: 'interviewfeedback1',
          name: 'interviewfeedback1',
          component: interviewfeedback1,
          meta: {
            title: '面试反馈(交付)',
            code: '4-5-1'
          }
        },
        {
          path: 'technicalInterview',
          name: 'technicalInterview',
          component: technicalInterview,
          meta: {
            title: '技术面试',
            code: '4-6'
          }
        },
        {
          path: 'technicalResults',
          name: 'technicalResults',
          component: technicalResults,
          meta: {
            title: '技术面试结果',
            code: '4-7'
          }
        },
        {
          path: 'entryapply',
          name: 'entryapply',
          component: entryapply,
          meta: {
            title: '入职申请',
            code: '5-1'
          }
        },
        {
          path: 'entryhandle',
          name: 'entryhandle',
          component: entryhandle,
          meta: {
            title: '入职办理',
            code: '5-2'
          }
        },
        {
          path: 'entrytracking',
          name: 'entrytracking',
          component: entrytracking,
          meta: {
            title: '进场跟踪',
            code: '5-3'
          }
        },
        {
          path: 'backchecked',
          name: 'backchecked',
          component: backchecked,
          meta: {
            title: '背景调查',
            code: '5-4'
          }
        },
        {
          path: 'teamconfigure',
          name: 'teamconfigure',
          component: teamconfigure,
          meta: {
            title: '添加组织',
            code: '6-12'
          }
        },
        {
          path: 'modelmanage',
          name: 'modelmanage',
          component: modelmanage,
          meta: {
            title: '客户简历',
            code: '5-5'
          }
        },
        {
          path: 'rolemanage',
          name: 'rolemanage',
          component: rolemanage,
          meta: {
            title: '角色管理',
            code: '6-1'
          }
        },
        {
          path: 'custmanage',
          name: 'custmanage',
          component: custmanage,
          meta: {
            title: '用户管理',
            code: '6-2'
          }
        },
        {
          path: 'postmanage',
          name: 'postmanage',
          meta: {
            title: '职位设置',
            code: '6-3'
          },
          component: postmanage,
          children: []
        },
        {
          path: 'employunitset',
          name: 'employunitset',
          component: employunitset,
          meta: {
            title: '客户设置',
            code: '6-4'
          },
          children: []
        },
        {
          path: 'districtmanage',
          name: 'districtmanage',
          component: districtmanage,
          meta: {
            title: '地区设置',
            code: '6-5'
          },
          children: []
        },
        {
          path: 'permissionset',
          name: 'permissionset',
          component: permissionset,
          meta: {
            title: '权限设置',
            code: '6-6'
          },
          children: []
        },
        {
          path: 'menuset',
          name: 'menuset',
          component: menuset,
          meta: {
            title: '菜单设置',
            code: '6-9'
          },
          children: []
        },
        {
          path: 'marquee',
          name: 'marquee',
          component: marquee,
          meta: {
            title: '字幕设置',
            code: '6-7'
          },
          children: []
        },
        {
          path: 'interviewprocess',
          name: 'interviewprocess',
          component: interviewprocess,
          meta: {
            title: '面试流程',
            code: '6-8'
          },
          children: []
        },
        {
          path: 'accessInfo',
          name: 'accessInfo',
          component: accessInfo,
          meta: {
            title: '访问记录',
            code: '6-14'
          }
        },
        {
          path: 'templatemanage',
          name: 'templatemanage',
          component: templatemanage,
          meta: {
            title: '简历模板',
            code: '6-10'
          },
          children: []
        },
        {
          path: 'personnelresume',
          name: 'personnelresume',
          component: personnelresume,
          meta: {
            title: '人员简历',
            code: '6-11'
          },
          children: []
        },
        {
          path: 'orgstructure',
          name: 'orgstructure',
          component: orgstructure,
          meta: {
            title: '组织结构',
            code: '7-1'
          }
        },
        {
          path: 'tasksetting',
          name: 'tasksetting',
          component: tasksetting,
          meta: {
            title: '任务设置',
            code: '7-2'
          },
          children: []
        },
        {
          path: 'dictionaryvalue',
          name: 'DictionaryValue',
          component: DictionaryValue,
          meta: {
            title: '岗位字典值',
            code: '7-3'
          },
          children: []
        },
        {
          path: 'timeValue',
          name: 'timeValue',
          component: timeValue,
          meta: {
            title: '时间字典值',
            code: '7-4'
          },
          children: []
        },
        {
          path: 'datadictionary',
          name: 'datadictionary',
          component: datadictionary,
          meta: {
            title: '数据字典',
            code: '7-5'
          },
          children: []
        },
        {
          path: 'resumepushstatistics',
          name: 'resumepushstatistics',
          component: resumepushstatistics,
          meta: {
            title: '简历推送统计表',
            code: '9-4'
          },
          children: []
        },
        {
          path: 'entrystatistics',
          name: 'entrystatistics',
          component: entrystatistics,
          meta: {
            title: '入职统计表',
            code: '9-5'
          },
          children: []
        },
        {
          path: 'outsourcedsheet',
          name: 'outsourcedsheet',
          component: outsourcedsheet,
          meta: {
            title: '外包人员增减表',
            code: '9-6'
          },
          children: []
        },
        {
          path: 'employinfosheet',
          name: 'employinfosheet',
          component: employinfosheet,
          meta: {
            title: '入职人员信息表',
            code: '9-7'
          },
          children: []
        }, {
          path: 'workstatistics',
          name: 'workstatistics',
          component: workstatistics,
          meta: {
            title: '工作统计表',
            code: '9-8'
          },
          children: []
        }, {
          path: 'mailtemplate',
          name: 'mailtemplate',
          component: mailtemplate,
          meta: {
            title: '邮件模板',
            code: '9-9'
          },
          children: []
        }, {
          path: 'resignationInformation',
          name: 'resignationInformation',
          component: resignationInformation,
          meta: {
            title: '离职信息表',
            code: '6-13'
          },
          children: []
        }, {
          path: 'entryInformation',
          name: 'entryInformation',
          component: entryInformation,
          meta: {
            title: '入职信息表',
            code: '6-14'
          },
          children: []
        },
        {
          path: "*",
          component: notFound,
          name: notFound,
          meta: {
            title: '暂无该页面',
            code: "0"
          },
        }
      ]
    },
  ]
})
router.beforeEach((to, from, next) => {
  let target = to.name;
  if (target == 'login') {
    if (tagsView.state.isLogin === true) {
      axios.post(Vue.prototype.url + '/user/iflogin').then(res => {
        if (res.data.code == 201003) {
          tagsView.commit('changeLoginState', false)
          next()
        } else if (res.data.code == 200) {
          if (tagsView.state.identity == 2) {
            next("/home/todaytaskleader")
          } else if (tagsView.state.identity == 3) {
            next("/home/todaytask2")
          } else if (tagsView.state.identity == 4) {
            next("/home/todaytask")
          } else if (tagsView.state.identity == 8) {
            next("/home/instorage")
          } else if (tagsView.state.identity == 12 || tagsView.state.identity == 13) {
            next("/home/technicalInterview");
          } else {
            next("/home")
          }
        }
      })
    } else if (tagsView.state.isLogin === false) {
      next()
    }
  } else if (target !== 'login') {
    if (target == 'honour') {
      next()
    } else if (tagsView.state.isLogin === false) {
      next('/')
    } else {
      axios.post(Vue.prototype.url + '/user/iflogin').then(res => {
        if (res.data.code == 201003) {
          tagsView.commit('changeLoginState', false)
          next('/')
        } else if (res.data.code == 200) {
          if (tagsView.state.identity == 12 || tagsView.state.identity == 13) {
            if (target !== 'technicalInterview') {
              tagsView.dispatch("delAllViews");
              const routes = {
                fullPath: "/home/technicalInterview",
                meta: {
                  code: "4-6",
                  title: "技术面试"
                },
                name: "technicalInterview"
              };
              tagsView.dispatch('addView', routes)
              next("/home/technicalInterview");
            } else {
              tagsView.dispatch("delAllViews");
              const routes = {
                name: to.name,
                meta: to.meta,
                fullPath: to.fullPath
              }
              tagsView.dispatch('addView', routes)
              next();
            }
          } else {
            next();
          }
        } else {
          next()
        }
      })
    }
  }
})

export default router

